package com.xyc.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xyc.model.EbNews;
import com.xyc.model.EbProduct;
import com.xyc.model.EbProductCategory;
import com.xyc.service.EbNewsService;
import com.xyc.service.EbProductCategoryService;
import com.xyc.service.EbProductService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller//证---访问首页
@RequestMapping("/index")
public class indexController {
    @Autowired
    private EbProductService ebProductService;
    @Autowired
    private EbNewsService ebNewsService;
    @Autowired
    private EbProductCategoryService ebProductCategoryService;

    @RequestMapping("/front")//前台
    public String index(@RequestParam(defaultValue = "1")int psize,
                        @RequestParam(defaultValue = "8")int pageSize,
                        @RequestParam(defaultValue = "1")int time,
                        @RequestParam(defaultValue = "10")int pageTime,

                        Model model, HttpServletRequest request){
        Page<EbProduct>productPage=ebProductService.list(psize,pageSize);
        Page<EbNews>newsPage=ebNewsService.list(time,pageTime);
        Map<String, List<EbProductCategory>> cateMap = ebProductCategoryService.selectBigAndSmallCate();
        model.addAttribute("productPage",productPage);
        model.addAttribute("newsPage",newsPage);
        //model.addAttribute("cateMap",cateMap);
        request.getSession().setAttribute("cateMap",cateMap);
        System.out.println("访问前台首页");
        return "index";
    }

}
